﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;

namespace WebSite_CodeMan
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {

        }

        protected void Session_Start(object sender, EventArgs e)
        {

        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            for (int i = 0; i < Request.QueryString.Count; i++)
            {
                if (Common.CheckMes.CheckKeyWord(Request.QueryString[i].ToString()))
                {
                    BLL.LogInfo.AddSysLog("【" + Request.Url.AbsolutePath + "】Url含有特殊字符！");
                    Response.Redirect("~/Error.html");
                }
            }
        }
        protected void Application_Error(object sender, EventArgs e)
        {
            Exception objErr = Server.GetLastError().GetBaseException();
            Server.ClearError();
            try
            {
                BLL.LogInfo.AddSysLog("【" + Request.Url.AbsolutePath + "】" + Server.HtmlEncode(objErr.Message));
            }
            catch (Exception ex)
            {
                Common.FileComm.WriteFile(Server.MapPath("~/ErrorLog/log.log"), "\n\t【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "】\n\t【错误1】" + objErr.Message + "\n\t【错误2】" + ex.Message);
            }
            Response.Redirect("~/Error.html");
        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}